<template>
  <div class="app-container">
    <el-tabs v-model="activeFinish" @tab-click="handleFinishClick">
      <el-tab-pane label="未结题" name="first"></el-tab-pane>
      <el-tab-pane label="已结题" name="second"></el-tab-pane>
    </el-tabs>
    <el-form :model="queryProject" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
            v-model="queryProject.projectName"
            placeholder="请输入项目名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目编号" prop="code">
        <el-input
            v-model="queryProject.code"
            placeholder="请输入项目编号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目负责人" prop="projectLeader">
        <el-input
            v-model="queryProject.projectLeader"
            placeholder="请输入项目负责人"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="itemList">
      <el-table-column label="项目编号" align="center" width="200" prop="code"/>
      <el-table-column label="项目名称" align="center" prop="projectName" width="220"/>
      <el-table-column label="项目负责人" align="center" prop="projectLeader" width="120"/>
      <el-table-column label="样品详情信息" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="toSample(scope.row.projectId)">详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="实验详情信息" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="toExperiment(scope.row.projectId)">详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="岗位结算信息" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="showPost(scope.row.projectId)">详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="实验费用信息" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="showExperiment(scope.row.projectId)">详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="归档" align="center">
        <template #default="scope">
          <el-button v-if="activeFinish=='first'" type="primary" @click="toSummarize(scope.row.projectId)">上传</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button v-if="activeFinish=='first'" type="success" @click="finish(scope.row.projectId)">结题</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="totalProject>0"
        :total="totalProject"
        v-model:page="queryProject.pageNum"
        v-model:limit="queryProject.pageSize"
        @pagination="getList"
    />

    <!-- 岗位列表 -->
    <el-dialog title="岗位列表" v-model="openPost" width="1000px" append-to-body style=" border-radius: 20px;">
      <el-tabs v-model="activeName" @tab-click="handlePostClick">
        <el-tab-pane label="未确认" name="first"></el-tab-pane>
        <el-tab-pane label="已确认" name="second"></el-tab-pane>
      </el-tabs>
      <el-form :model="queryPost" ref="queryPostRef" :inline="true" v-show="showPost" label-width="90px">
        <el-form-item label="项目负责人" prop="job">
          <el-input
              v-model="queryPost.job"
              placeholder="请输入项目负责人"
              clearable
              @keyup.enter="handleQueryPost"
          />
        </el-form-item>
        <el-form-item label="样品编号" prop="sampleName">
          <el-input
              v-model="queryPost.sampleName"
              placeholder="请输入样品编号"
              clearable
              @keyup.enter="handleQueryPost"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQueryPost">搜索</el-button>
          <el-button icon="Refresh" @click="resetQueryPost">重置</el-button>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="checkPosts()">确认</el-button>
      <el-table :data="postList" @selectionChange="handleSelectionChangePost">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="实验数据编号" align="center" width="120" prop="experimentId"/>
        <el-table-column label="岗位负责人" align="center" prop="job"/>
        <el-table-column label="样品编号" align="center" prop="sampleName"/>
        <el-table-column label="实验" align="center" prop="type"/>
        <el-table-column label="实验时间" align="center" prop="experimentDate"/>
        <el-table-column v-if="checkRole(['showall'])" label="价格" fixed="right" align="center" prop="jobPrice">
          <template #default="scope">
            {{scope.row.jobPrice/100}}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="200" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button v-if="activeName=='first'" type="primary" @click="confirmP(scope.row.experimentId)">确认
            </el-button>
<!--            <el-button v-if="activeName=='first'" type="warning" @click="showUpdatePost(scope.row.experimentId,scope.row.sampleName,scope.row.type,scope.row.jobPrice)">修改</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <pagination
          v-show="totalPost>0"
          :total="totalPost"
          v-model:page="queryPost.pageNum"
          v-model:limit="queryPost.pageSize"
          @pagination="listP"
      />
    </el-dialog>
    <!-- 修改岗位信息   -->
    <el-dialog title="岗位价格修改" v-model="openUpdatePost" width="400px" append-to-body style=" border-radius: 20px;">
      <el-form :model="postForm">
        <el-form-item label="样品" prop="sampleName">
          <el-input v-model="postForm.sampleName" disabled />
        </el-form-item>
        <el-form-item label="实验" prop="type">
          <el-input v-model="postForm.type" disabled />
        </el-form-item>
        <el-form-item label="价格" prop="jobPrice">
          <el-input v-model="postForm.jobPrice"/>
        </el-form-item>
        <el-button type="primary" @click="updateP">修改</el-button>
      </el-form>
    </el-dialog>
    <!-- 实验列表  -->
    <el-dialog title="实验列表" v-model="openExperiment" width="1000px" append-to-body style=" border-radius: 20px;">
      <el-tabs v-model="activeName" @tab-click="handleExperimentClick">
        <el-tab-pane label="未确认" name="first"></el-tab-pane>
        <el-tab-pane label="已确认" name="second"></el-tab-pane>
      </el-tabs>
      <el-form :model="queryExperiment" ref="queryExperimentRef" :inline="true" v-show="showExperiment"
               label-width="90px">
        <el-form-item label="样品编号" prop="sampleName">
          <el-input
              v-model="queryExperiment.sampleName"
              placeholder="请输入样品编号"
              clearable
              @keyup.enter="handleQueryExperiment"
          />
        </el-form-item>
        <el-form-item label="实验名称" prop="type">
          <el-input
              v-model="queryExperiment.type"
              placeholder="请输入实验名称"
              clearable
              @keyup.enter="handleQueryExperiment"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQueryExperiment">搜索</el-button>
          <el-button icon="Refresh" @click="resetQueryExperiment">重置</el-button>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="confirmEs()">确认</el-button>
      <el-table :data="experimentList" @selectionChange="handleSelectionChangeExperiment">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="样品编号" align="center" prop="sampleName"/>
        <el-table-column label="实验" align="center" prop="type"/>
        <el-table-column v-if="checkRole(['showall'])" label="单价(元)" align="center" prop="experimentPrice">
          <template #default="scope">
            {{ scope.row.experimentPrice/100}}
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" prop="experimentNumber"/>
        <el-table-column v-if="checkRole(['showall'])" label="总价(元)" fixed="right" align="center">
          <template #default="scope">
            {{ scope.row.experimentPrice * scope.row.experimentNumber/100 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="200" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button v-if="activeName=='first'" type="primary" @click="confirmE(scope.row.experimentId)">确认
            </el-button>
<!--            <el-button v-if="activeName=='first'" type="warning" @click="showUpdateExp(scope.row.experimentId,scope.row.sampleName,scope.row.type,scope.row.experimentPrice,scope.row.experimentNumber)">修改</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <pagination
          v-show="totalExperiment>0"
          :total="totalExperiment"
          v-model:page="queryExperiment.pageNum"
          v-model:limit="queryExperiment.pageSize"
          @pagination="listP"
      />
    </el-dialog>
    <!-- 修改实验信息   -->
    <el-dialog title="实验价格修改" v-model="openUpdateExp" width="400px" append-to-body style=" border-radius: 20px;">
      <el-form :model="expForm">
        <el-form-item label="样品" prop="sampleName">
          <el-input v-model="expForm.sampleName" disabled />
        </el-form-item>
        <el-form-item label="实验" prop="type">
          <el-input v-model="expForm.type" disabled />
        </el-form-item>
        <el-form-item label="实验价格" prop="experimentPrice">
          <el-input v-model="expForm.experimentPrice"/>
        </el-form-item>
        <el-form-item label="实验数量" prop="experimentNumber">
          <el-input v-model="expForm.experimentNumber"/>
        </el-form-item>
        <el-form-item label="实验总价">
            {{ parseInt(expForm.experimentPrice * expForm.experimentNumber*100)/100 }}
        </el-form-item>
        <el-button type="primary" @click="updateE">修改</el-button>
      </el-form>
    </el-dialog>
    <!--  步骤条  -->
    <el-dialog v-model="openSteps" width="650" align-center append-to-body style=" border-radius: 20px;">
      <el-steps style="max-width: 600px" :active="activeStep" align-center>
        <el-step title="项目录入"/>
        <el-step title="样品录入"/>
        <el-step title="实验录入"/>
        <el-step title="实验中"/>
        <el-step title="财务结算"/>
        <el-step title="结题"/>
      </el-steps>
    </el-dialog>
    <!-- 实验详情 -->
    <el-dialog v-model="showExperimentDetails"  append-to-body style="width: 800px; border-radius: 20px;">

      <el-table v-loading="loading2" :data="experimentDetailsData" :span-method="marge">
        <el-table-column prop="sampleName" label="样品编号" align="center"></el-table-column>
        <el-table-column prop="type" label="实验名称" align="center"></el-table-column>
        <el-table-column prop="experimentNumber" label="实验数量" align="center"></el-table-column>
        <el-table-column prop="experimentRemark" label="实验备注" align="center"/>
        <el-table-column prop="experimentRequiredDate" label="完成日期进度" align="center">
          <template #default="scope">
            <div v-if="scope.row.experimentDate!=null && scope.row.experimentRequiredDate!=null">
              <span v-if="getJD(scope.row.experimentDate,scope.row.experimentRequiredDate)>=100">
                100%
              </span>
              <span style="color: red" v-else-if="getJD(scope.row.experimentDate,scope.row.experimentRequiredDate)>50">
                {{getJD(scope.row.experimentDate,scope.row.experimentRequiredDate)}}%
              </span>
              <span v-else>
                {{getJD(scope.row.experimentDate,scope.row.experimentRequiredDate)}}%
              </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="expermentType" label="实验状态" align="center" width="100">
          <template #default="scope">
            <div v-if="scope.row.expermentType%10>=2" style="background-color: #0a8805;color: white;border-radius: 30%;font-size: 12px">
              已完成
            </div>
            <div v-else style="background-color: #dc1717;color: white;border-radius: 30%;font-size: 12px">
              未完成
            </div>
          </template>
        </el-table-column>

      </el-table>

      <pagination
          v-show="totalExperimentDetails>0"
          :total="totalExperimentDetails"
          v-model:page="queryExperiment.pageNum"
          v-model:limit="queryExperiment.pageSize"
          @pagination="getExperimentDetails"
      />

    </el-dialog>
    <!-- 归档 -->
    <el-dialog v-model="openSummarize" style="width: 1000px;">
      <el-form ref="queryRef" :inline="true" label-width="200px" label-position="top">
        <!--任务书、协议书、科研合同-->
        <el-form-item label="任务书、协议书、科研合同：" prop="rxk" style="width: 100%;" label-width="130px">
          <el-radio-group v-model="typeForm.rxk">
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.rxk.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.rxk == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.rxk"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'rxk')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>
          <el-card v-if="typeForm.rxk==0" v-for="(file, index) in fileForm.rxk" :key="index"
                   style="width: 800px;margin-top: 20px;">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'rxk')" v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.rxk" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <!--试验、试验、测试分析报告单-->
        <el-form-item label="实验、试验、测试分析报告单：" prop="sscBgd" style="width: 100%;" label-width="130px">
          <el-radio-group v-model="typeForm.sscBgd" >
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.sscBgd.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.sscBgd == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.sscBgd"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'sscBgd')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>

          <el-card v-if="typeForm.sscBgd==0" v-for="(file, index) in fileForm.sscBgd" :key="index" style="width: 800px">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'sscBgd')"
                         v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.sscBgd" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <!--科研合同验收文件材料-->
        <el-form-item label="科研合同验收文件材料：" prop="kyht" style="width: 100%;" label-width="130px">
          <el-radio-group v-model="typeForm.kyht" >
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.kyht.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.kyht == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.kyht"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'kyht')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>

          <el-card v-if="typeForm.kyht==0" v-for="(file, index) in fileForm.kyht" :key="index" style="width: 800px">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'kyht')"
                         v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.kyht" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <!--全部实验、试验、测试分析相关资料电子版-->
        <el-form-item label="全部实验、试验、测试分析相关资料电子版：" prop="sscZl" style="width: 100%;"
                      label-width="130px">
          <el-radio-group v-model="typeForm.sscZl" >
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.sscZl.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.sscZl == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.sscZl"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'sscZl')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>

          <el-card v-if="typeForm.sscZl==0" v-for="(file, index) in fileForm.sscZl" :key="index" style="width: 800px">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'sscZl')"
                         v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.sscZl" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <!--项目经费决算-->
        <el-form-item label="项目经费决算：" prop="xmjf" style="width: 100%;" label-width="130px">
          <el-radio-group v-model="typeForm.xmjf" >
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.xmjf.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.xmjf == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.xmjf"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'xmjf')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>

          <el-card v-if="typeForm.xmjf==0" v-for="(file, index) in fileForm.xmjf" :key="index" style="width: 800px">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'xmjf')"
                         v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.xmjf" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <!--文件归档情况确认表-->
        <el-form-item label="文件归档情况确认表：" prop="wjgd" style="width: 100%;" label-width="130px">
          <el-radio-group v-model="typeForm.wjgd" >
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.wjgd.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.wjgd == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.wjgd"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'wjgd')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>

          <el-card v-if="typeForm.wjgd==0" v-for="(file, index) in fileForm.wjgd" :key="index" style="width: 800px">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'wjgd')"
                         v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.wjgd" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <!--文件材料归档审查表-->
        <el-form-item label="文件材料归档审查表：" prop="wjcl" style="width: 100%;" label-width="130px">
          <el-radio-group v-model="typeForm.wjcl" >
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.wjcl.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.wjcl == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.wjcl"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'wjcl')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>

          <el-card v-if="typeForm.wjcl==0" v-for="(file, index) in fileForm.wjcl" :key="index" style="width: 800px">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'wjcl')"
                         v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.wjcl" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <!--必要的归档说明及归档补充文件材料等-->
        <el-form-item label="必要的归档说明及归档补充文件材料等：" prop="gdsm" style="width: 100%;" label-width="130px">
          <el-radio-group v-model="typeForm.gdsm" >
            <el-radio :label="0" size="large" :disabled="disabled">是</el-radio>
            <el-radio :label="1" size="large" :disabled="disabled || fileForm.gdsm.length!=0 ">否</el-radio>
          </el-radio-group>
          <el-upload
              v-if="typeForm.gdsm == 0"
              style="margin-left: 2%;"
              v-model:file-list="fileForm.gdsm"
              :action='baseurl+"/common/upload"'
              :on-success="(response, uploadFile, uploadFiles)=>upload(response, uploadFile, uploadFiles,'gdsm')"
              :show-file-list="false"
          >
            <el-button type="primary" :disabled="disabled">上传</el-button>
          </el-upload>

          <el-card v-if="typeForm.gdsm==0" v-for="(file, index) in fileForm.gdsm" :key="index" style="width: 800px">
            <div slot="header" class="clearfix">
              <span>{{ file.name }}</span>
              <el-button style="float: right; margin-left: 2%" type="danger" link @click="remove(file,'gdsm')"
                         v-if="!disabled">
                删除
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="primary" link @click="handleDownload(file)">
                下载
              </el-button>
              <el-button style="float: right; margin-left: 2%" type="warning" link @click="handlePreview(file)">
                查看
              </el-button>
            </div>
          </el-card>
          <el-input :readonly="disabled" v-else v-model="reasonForm.gdsm" placeholder="请输入报告单理由:"
                    style="width: 50%;margin-left: 20px" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea"></el-input>
        </el-form-item>
        <div style="width: 100%">
          <el-button type="success" :disabled="disabled" style="margin-left: 34%" @click="submit()">归档</el-button>
          <el-button type="danger" :disabled="disabled" @click="()=>openSummarize=false">取消</el-button>
          <el-button type="success" :disabled="disabled" style="margin-left: 34%" @click="save()">暂存</el-button>
        </div>
      </el-form>
    </el-dialog>
    <!-- 文件预览 -->
    <el-dialog
        title="文件预览"
        v-model="openPreview"
        :close-on-click-modal="true"
        :close-on-press-escape="true"
        :show-close="true"
        :width="800"
    >
      <vue-office-docx
          v-if="file.extension === 'docx'"
          :src="file.filePath"
          style="height: 100vh;"
      />
      <vue-office-excel
          v-else-if="file.extension === 'xlsx'"
          :src="file.filePath"
          style="height: 100vh;"
      />
      <vue-office-pdf
          v-else-if="file.extension === 'pdf'"
          :src="file.filePath"
      />
      <el-image v-else-if="file.extension === 'jpg' ||file.extension === 'png' || file.extension === 'gif'"
                style="width: 100%" :src="file.filePath" fit="contain"/>
      <span v-else>该格式文件暂不支持阅览！</span>
    </el-dialog>
  </div>
</template>

<script setup name="HandleItem">
import {
  backExperiment, backExperiments,
  backPost,
  backPosts,
  confirmExperiment, confirmExperiments,
  confirmPost, confirmPosts,
  listExperiment, listExperimentDetails,
  listPost,
  listProject, toFinish, updateExperiment
} from "@/api/project/handle.js";
import {ElMessage, ElMessageBox, ElNotification} from "element-plus";
import router from "@/router/index.js";
import {insertSummarize, listSummarize, removeFile} from "@/api/summarize/summarize.js";
import VueOfficeExcel from "@vue-office/excel";
import VueOfficePdf from "@vue-office/pdf";
import VueOfficeDocx from "@vue-office/docx";
import {ref} from "vue";
import {checkRole} from "@/utils/permission.js";

const {proxy} = getCurrentInstance();

const itemList = ref([]);

const loading = ref(true);
const showSearch = ref(true);
const single = ref(true);
const multiple = ref(true);
const totalProject = ref(0);
const title = ref("");
const openSteps = ref(false);
const activeStep = ref(0);
const activeFinish = ref('first');


const stepList = ref([
  {style: {'background-color': '#7FFF00'}, t1: '项目录入', t2: '项目管理员'},
  {style: {'background-color': '#15B707'}, t1: '样品录入', t2: '样品管理员'},
  {style: {'background-color': '#31CCF1'}, t1: '实验录入', t2: '实验管理员'},
  {style: {'background-color': '#F62D25'}, t1: '实验中', t2: '实验分发员'},
  {style: {'background-color': '#EDEF1E'}, t1: '财务结算', t2: '财务'},
  {style: {'background-color': '#3E59DC'}, t1: '结题', t2: '项目负责人'}
])

const data = reactive({
  queryProject: {
    pageNum: 1,
    pageSize: 10,
    projectName: null,
    code: null,
    finish: false
  },
  queryPost: {
    pageNum: 1,
    pageSize: 5,
    hasConfirm: false
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    projectId: pid,
    sampleName: null,
    experimentName: null,
  },
  queryExperiment: {
    pageNum: 1,
    pageSize: 10,
    hasConfirm: false,
    projectId: pid,
    sampleName: null,
    experimentName: null,
  },
  rules: {},
  fileList: {
    rxk: [],
    sscBgd: [],
    kyht: [],
    sscZl: [],
    xmjf: [],
    wjgd: [],
    wjcl: [],
    gdsm: [],
    other: [],
  },
  file: {
    fileName: null,
    filePath: null,
    extension: null,
  }
});

const {
  queryProject,
  queryExperiment,
  queryPost,
  rules,
  queryParams,
  fileList,
  file
} = toRefs(data);

function showStep(i) {
  activeStep.value = i;
  openSteps.value = true;
}

function handleFinishClick(tab) {
  if (tab.props.name == 'second') {
    queryProject.value.finish = true;
  } else {
    queryProject.value.finish = false;
  }
  getList();
}

/** 列表 */
function getList() {
  loading.value = true;
  listProject(queryProject.value).then(res => {
    itemList.value = res.rows;
    totalProject.value = res.total;
    loading.value = false;
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryProject.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

function toSample(id) {
  router.push({path: '/project/sdetails', query: {id: id,finish:activeFinish.value=='second'?1:0}});
}

//实验详情
const showExperimentDetails = ref(false);
const experimentDetailsData = ref();
const totalExperimentDetails = ref(0);
const loading2 = ref(false);

function toExperiment(id) {
  loading2.value = true;
  showExperimentDetails.value = true;
  queryExperiment.value.projectId = id;
  getExperimentDetails();
}

function getExperimentDetails() {
  has = new Set();
  experimentDetailsData.value = []
  listExperimentDetails(queryExperiment.value).then(res => {
    experimentDetailsData.value = res.rows;
    totalExperimentDetails.value = res.total;
    loading2.value = false;
  });
}

//以存在的父样品ID
let has = new Set();

function marge({row, column, rowIndex, columnIndex}) {
  if (columnIndex == 0) {
    if (!has.has(row.sampleId)) {
      let c = 0
      for (let i = 0; i < experimentDetailsData.value.length; i++) {
        if (experimentDetailsData.value[i].sampleId == row.sampleId)
          c++;
      }
      has.add(row.sampleId);
      return {rowspan: c, colspan: 1}
    } else {
      return {rowspan: 0, colspan: 1}
    }
  }
}

var pid;
//岗位模块
const openPost = ref(false);
const postList = ref([]);
const totalPost = ref(0);
const activeName = ref("first");

function handlePostClick(tab) {
  if (tab.props.name == 'first') {
    queryPost.value.hasConfirm = false;
    handleQueryPost();
  } else {
    queryPost.value.hasConfirm = true;
    handleQueryPost();
  }
}

function showPost(id) {
  activeName.value = 'first';
  queryExperiment.value.hasConfirm = false;
  pid = id;
  openPost.value = true;
  handleQueryPost();
}

function listP() {
  queryPost.value.projectId = pid;
  listPost(queryPost.value).then(res => {
    postList.value = res.rows;
    totalPost.value = res.total;
  })
}

function handleQueryPost() {
  queryPost.value.pageNum = 1;
  listP();
}

const postIds = ref([]);

function handleSelectionChangePost(selection) {
  postIds.value = selection.map(item => item.experimentId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

function resetQueryPost() {
  proxy.resetForm("queryPostRef");
  handleQueryPost();
}

function confirmP(id) {
  confirmPost(id).then(res => {
    handleQueryPost();
    ElNotification({
      title: '成功',
      message: '已确认该条信息',
      type: 'success'
    })
  })
}

function checkPosts() {
  ElMessageBox.confirm(
      '是否要全部确认吗?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info',
      }
  ).then(() => {
    confirmPosts({ids: postIds.value}).then((res) => {
      ElNotification({
        title: '成功',
        message: '确认成功',
        type: 'success'
      })
      handleQueryPost();
    })
  }).catch(() => {
  })
}
//修改岗位
const postForm=ref({});
const openUpdatePost=ref(false);

function showUpdatePost(expId,sampleName,type,price){
  postForm.value.experimentId=expId;
  postForm.value.sampleName=sampleName;
  postForm.value.type=type;
  postForm.value.jobPrice=price/100;
  openUpdatePost.value=true;
}
function updateP(){
  postForm.value.jobPrice=postForm.value.jobPrice*100;
  updateExperiment(postForm.value).then(res=>{
    handleQueryPost();
    ElNotification({title:'提示',message:'修改成功',type:'success'})
    openUpdatePost.value=false;
  })
}
//修改实验
const expForm=ref({});
const openUpdateExp=ref(false);

function showUpdateExp(expId,sampleName,type,experimentPrice,experimentNumber){
  expForm.value.experimentId=expId;
  expForm.value.sampleName=sampleName;
  expForm.value.type=type;
  expForm.value.experimentPrice=experimentPrice/100;
  expForm.value.experimentNumber=experimentNumber;
  openUpdateExp.value=true;
}
function updateE(){
  expForm.value.experimentPrice=expForm.value.experimentPrice*100;
  updateExperiment(expForm.value).then(res=>{
    handleQueryExperiment();
    ElNotification({title:'提示',message:'修改成功',type:'success'})
    openUpdateExp.value=false;
  })
}

//实验列表
const openExperiment = ref(false);
const experimentList = ref([]);
const totalExperiment = ref(0);

function handleExperimentClick(tab) {
  if (tab.props.name == 'first') {
    queryExperiment.value.hasConfirm = false;
    handleQueryExperiment();
  } else {
    queryExperiment.value.hasConfirm = true;
    handleQueryExperiment();
  }
}

function showExperiment(id) {
  activeName.value = 'first';
  queryExperiment.value.hasConfirm = false;
  pid = id;
  handleQueryExperiment();
  openExperiment.value = true;
}

function listE() {
  queryExperiment.value.projectId = pid;
  listExperiment(queryExperiment.value).then(res => {
    experimentList.value = res.rows;
    totalExperiment.value = res.total;
  })
}

function handleQueryExperiment() {
  queryExperiment.value.pageNum = 1;
  listE();
}

const experimentIds = ref([]);

function handleSelectionChangeExperiment(selection) {
  experimentIds.value = selection.map(item => item.experimentId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

function resetQueryExperiment() {
  proxy.resetForm("queryExperimentRef");
  handleQueryExperiment();
}

function confirmE(id) {
  confirmExperiment(id).then(res => {
    handleQueryExperiment();
    ElNotification({
      title: '成功',
      message: '已确认该条信息',
      type: 'success'
    })
  })
}

function confirmEs() {
  ElMessageBox.confirm(
      '是否要全部确认吗?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info',
      }
  ).then(() => {
    confirmExperiments({ids: experimentIds.value}).then((res) => {
      ElNotification({
        title: '成功',
        message: '确认成功',
        type: 'success'
      })
      handleQueryExperiment();
    })
  }).catch(() => {
  })
}

function backE(id) {
  backExperiment(id).then(res => {
    handleQueryExperiment();
    ElNotification({
      title: '成功',
      message: '已退回该条信息',
      type: 'success'
    })
  })
}

function backEs() {
  ElMessageBox.confirm(
      '确认退回吗?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info',
      }
  ).then(() => {
    backExperiments({ids: experimentIds.value}).then((res) => {
      ElNotification({
        title: '成功',
        message: '退回成功',
        type: 'success'
      })
      handleQueryExperiment();
    })
  }).catch(() => {
  })
}

function finish(id) {
  toFinish(id).then(res => {
    console.log(res)
    if (res.msg=="") {
      getList();
      ElNotification({
        title: '提示',
        message: '该项目已结题',
        type: 'success'
      })
    } else {
      ElNotification({
        title: '提示',
        message: res.msg,
        type: 'warning'
      })
    }
  })
}


//归档模块
const baseurl = import.meta.env.VITE_APP_BASE_API;
const openSummarize = ref(false);
const disabled = ref(false);
const openPreview = ref(false);

const typeForm = ref({});//0为文件，1为原因
const fileForm = ref({rxk: [], sscBgd: [], kyht: [], sscZl: [], xmjf: [], wjgd: [], wjcl: [], gdsm: [], other: []});
const reasonForm = ref({});

function toSummarize(id) {
  pid = id;
  listSummarize(id).then(res => {
    parse(res.data);
    disabled.value = res.data.finish == 1;
    openSummarize.value = true;
  })
}

//解析后端传回的值
function parse(data) {
  //rxk
  typeForm.value.rxk = type(data.rxk);
  fileForm.value.rxk = parseFiles(data.rxk);
  reasonForm.value.rxk = parseReason(data.rxk);
  //sscBgd
  typeForm.value.sscBgd = type(data.sscBgd);
  fileForm.value.sscBgd = parseFiles(data.sscBgd);
  reasonForm.value.sscBgd = parseReason(data.sscBgd);
  //kyht
  typeForm.value.kyht = type(data.kyht);
  fileForm.value.kyht = parseFiles(data.kyht);
  reasonForm.value.kyht = parseReason(data.kyht);
  //sscZl
  typeForm.value.sscZl = type(data.sscZl);
  fileForm.value.sscZl = parseFiles(data.sscZl);
  reasonForm.value.sscZl = parseReason(data.sscZl);
  //xmjf
  typeForm.value.xmjf = type(data.xmjf);
  fileForm.value.xmjf = parseFiles(data.xmjf);
  reasonForm.value.xmjf = parseReason(data.xmjf);
  //wjgd
  typeForm.value.wjgd = type(data.wjgd);
  fileForm.value.wjgd = parseFiles(data.wjgd);
  reasonForm.value.wjgd = parseReason(data.wjgd);
  //wjcl
  typeForm.value.wjcl = type(data.wjcl);
  fileForm.value.wjcl = parseFiles(data.wjcl);
  reasonForm.value.wjcl = parseReason(data.wjcl);
  //gdsm
  typeForm.value.gdsm = type(data.gdsm);
  fileForm.value.gdsm = parseFiles(data.gdsm);
  reasonForm.value.gdsm = parseReason(data.gdsm);
  //other
  typeForm.value.other = 0;
  fileForm.value.other = parseFiles(data.other);
  reasonForm.value.other = parseReason(data.other);
}

//判断是否有文件
function type(str) {
  if (str == null || str == '')
    return 0;
  let type = str.slice(0, str.indexOf(':'));
  return type == 'file' ? 0 : 1;
}

//将字符串转换为文件数组
function parseFiles(str) {
  if (str == null || str == '' || type(str) == 1)
    return [];
  let filestr = str.slice(str.indexOf(':') + 1);
  let files = filestr.split(';');
  files.pop();
  let res = [];
  for (let f of files) {
    res.push({name: f.slice(f.lastIndexOf('/') + 1), url: f});
  }
  return res;
}

function parseReason(str) {
  if (str == null || str == '' || type(str) == 0)
    return '';
  let reason = str.slice(str.indexOf(':') + 1);
  return reason;
}

//将文件数组转为字符串
function toFile(files) {
  let f = 'file:';
  for (let file of files) {
    f += file.url + ';'
  }
  return f;
}

function toReason(reason) {
  return 'reason:' + reason;
}

//保存
function reasonToData() {
  let data = {projectId: pid};
  if (typeForm.value.rxk == 1) {
    data.rxk = toReason(reasonForm.value.rxk);
  }
  if (typeForm.value.sscBgd == 1) {
    data.sscBgd = toReason(reasonForm.value.sscBgd);
  }
  if (typeForm.value.kyht == 1) {
    data.kyht = toReason(reasonForm.value.kyht);
  }
  if (typeForm.value.sscZl == 1) {
    data.sscZl = toReason(reasonForm.value.sscZl);
  }
  if (typeForm.value.xmjf == 1) {
    data.xmjf = toReason(reasonForm.value.xmjf);
  }
  if (typeForm.value.wjgd == 1) {
    data.wjgd = toReason(reasonForm.value.wjgd);
  }
  if (typeForm.value.wjcl == 1) {
    data.wjcl = toReason(reasonForm.value.wjcl);
  }
  if (typeForm.value.gdsm == 1) {
    data.gdsm = toReason(reasonForm.value.gdsm);
  }
  if (typeForm.value.other == 1) {
    data.other = toReason(reasonForm.value.other);
  }
  return data;
}

function save() {
  let data = reasonToData();
  insertSummarize(data).then(res => {
    ElNotification({message: '保存成功！', type: 'success', title: '成功'});
  })
}

//归档
function submit() {
  if (typeForm.value.rxk==1 && (reasonForm.value.rxk==null || reasonForm.value.rxk=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  if (typeForm.value.sscBgd==1 && (reasonForm.value.sscBgd==null || reasonForm.value.sscBgd=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  if (typeForm.value.kyht==1 && (reasonForm.value.kyht==null || reasonForm.value.kyht=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  if (typeForm.value.sscZl==1 && (reasonForm.value.sscZl==null || reasonForm.value.sscZl=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  if (typeForm.value.xmjf==1 && (reasonForm.value.xmjf==null || reasonForm.value.xmjf=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  if (typeForm.value.wjgd==1 && (reasonForm.value.wjgd==null || reasonForm.value.wjgd=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  if (typeForm.value.wjcl==1 && (reasonForm.value.wjcl==null || reasonForm.value.wjcl=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  if (typeForm.value.gdsm==1 && (reasonForm.value.gdsm==null || reasonForm.value.gdsm=='')){
    ElMessage({message: '请填写理由！', type: 'warning'})
    return;
  }
  let data = reasonToData();
  data.finish = 1;
  insertSummarize(data).then(res => {
    ElNotification({message: '项目已归档！', type: 'success', title: '成功'});
    openSummarize.value = false;
  })
}

function handlePreview(f) {//文件预览
  file.value.fileName = f.name;
  file.value.filePath = f.url;
  file.value.extension = getFileExtension(f.name);
  openPreview.value = true;
}

function getFileExtension(filename) {
  return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
}

function handleDownload(file) {//文件下载
  const name = file.name.slice(0,file.name.lastIndexOf('_'))+file.name.slice(file.name.lastIndexOf('.'));
  console.log(name);
  const url = file.url;
  const a = document.createElement('a')
  a.download=name;
  a.setAttribute('download', name)
  a.setAttribute('target', '_blank')
  a.setAttribute('href', url)
  a.click()
}

function upload(response, file, abandon, param) {
  console.log('上传成功:', response)
  // 处理上传成功后的回调
  const fileInfo = {
    name: file.name,
    url: response.url  // 假设响应中包含了文件的访问路径
  };
  switch (param) {
    case 'rxk':
      fileForm.value.rxk.pop();
      fileForm.value.rxk.push(fileInfo);
      insertSummarize({projectId: pid, rxk: toFile(fileForm.value.rxk)}).then(res => {
      })
      break;
    case 'sscBgd':
      fileForm.value.sscBgd.pop();
      fileForm.value.sscBgd.push(fileInfo);
      insertSummarize({projectId: pid, sscBgd: toFile(fileForm.value.sscBgd)}).then(res => {
      })
      break;
    case 'kyht':
      fileForm.value.kyht.pop();
      fileForm.value.kyht.push(fileInfo);
      insertSummarize({projectId: pid, kyht: toFile(fileForm.value.kyht)}).then(res => {
      })
      break;
    case 'sscZl':
      fileForm.value.sscZl.pop();
      fileForm.value.sscZl.push(fileInfo);
      insertSummarize({projectId: pid, sscZl: toFile(fileForm.value.sscZl)}).then(res => {
      })
      break;
    case 'xmjf':
      fileForm.value.xmjf.pop();
      fileForm.value.xmjf.push(fileInfo);
      insertSummarize({projectId: pid, xmjf: toFile(fileForm.value.xmjf)}).then(res => {
      })
      break;
    case 'wjgd':
      fileForm.value.wjgd.pop();
      fileForm.value.wjgd.push(fileInfo);
      insertSummarize({projectId: pid, wjgd: toFile(fileForm.value.wjgd)}).then(res => {
      })
      break;
    case 'wjcl':
      fileForm.value.wjcl.pop();
      fileForm.value.wjcl.push(fileInfo);
      insertSummarize({projectId: pid, wjcl: toFile(fileForm.value.wjcl)}).then(res => {
      })
      break;
    case 'gdsm':
      fileForm.value.gdsm.pop();
      fileForm.value.gdsm.push(fileInfo);
      insertSummarize({projectId: pid, gdsm: toFile(fileForm.value.gdsm)}).then(res => {
      })
      break;
    case 'other':
      fileForm.value.other.pop();
      fileForm.value.other.push(fileInfo);
      insertSummarize({projectId: pid, other: toFile(fileForm.value.other)}).then(res => {
      })
      break;
  }
}

function remove(file, param) {
  let fname = file.url.slice(file.url.indexOf('/upload'));
  switch (param) {
    case 'rxk':
      for (let i = 0; i < fileForm.value.rxk.length; i++) {
        if (fileForm.value.rxk[i].name === file.name) {
          fileForm.value.rxk.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, rxk: toFile(fileForm.value.rxk)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'sscBgd':
      for (let i = 0; i < fileForm.value.sscBgd.length; i++) {
        if (fileForm.value.sscBgd[i].name === file.name) {
          fileForm.value.sscBgd.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, sscBgd: toFile(fileForm.value.sscBgd)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'kyht':
      for (let i = 0; i < fileForm.value.kyht.length; i++) {
        if (fileForm.value.kyht[i].name === file.name) {
          fileForm.value.kyht.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, kyht: toFile(fileForm.value.kyht)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'sscZl':
      for (let i = 0; i < fileForm.value.sscZl.length; i++) {
        if (fileForm.value.sscZl[i].name === file.name) {
          fileForm.value.sscZl.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, sscZl: toFile(fileForm.value.sscZl)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'xmjf':
      for (let i = 0; i < fileForm.value.xmjf.length; i++) {
        if (fileForm.value.xmjf[i].name === file.name) {
          fileForm.value.xmjf.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, xmjf: toFile(fileForm.value.xmjf)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'wjgd':
      for (let i = 0; i < fileForm.value.wjgd.length; i++) {
        if (fileForm.value.wjgd[i].name === file.name) {
          fileForm.value.wjgd.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, wjgd: toFile(fileForm.value.wjgd)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'wjcl':
      for (let i = 0; i < fileForm.value.wjcl.length; i++) {
        if (fileForm.value.wjcl[i].name === file.name) {
          fileForm.value.wjcl.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, wjcl: toFile(fileForm.value.wjcl)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'gdsm':
      for (let i = 0; i < fileForm.value.gdsm.length; i++) {
        if (fileForm.value.gdsm[i].name === file.name) {
          fileForm.value.gdsm.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, gdsm: toFile(fileForm.value.gdsm)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
    case 'other':
      for (let i = 0; i < fileForm.value.other.length; i++) {
        if (fileForm.value.other[i].name === file.name) {
          fileForm.value.other.splice(i, 1);
        }
      }
      insertSummarize({projectId: pid, other: toFile(fileForm.value.other)}).then(res => {
        removeFile(fname).then(res => {
        })
      })
      break;
  }

}
function getJD(startDate,endDate){
  let st = Date.parse(startDate)-28800000;
  let en = Date.parse(endDate)-28800000;
  let curr = Date.now();
  let t=(curr-st)/(en-st)*100;
  return parseInt(t);
}


getList();

</script>
